package cool.houge.pig.model;

import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Persistable;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

/**
 * 用户认证：授权码.
 *
 * @author KK (kzou227@qq.com)
 */
@Table("t_auth_authorization_code")
@Data
public class AuthAuthorizationCode implements Persistable<Long> {

  @Getter(value = AccessLevel.NONE)
  @Setter(value = AccessLevel.NONE)
  private transient boolean _new;
  // =====================================================================================//
  /** 主键. */
  private @Id Long id;
  /** 用户ID. */
  private @Column Long uid;
  /** 授权的客户端ID. */
  private @Column("client_id") String clientId;
  /** 授权码. */
  private @Column("authorization_code") String authorizationCode;
  /** 重定向URI. */
  private @Column("redirect_uri") String redirectUri;
  /** 过期时间. */
  private @Column("expire_time") LocalDateTime expireTime;
  /** 数据版本（乐观锁）. */
  private @Column Integer ver;
  /** 更新时间. */
  private @Column("update_time") LocalDateTime updateTime;
  /** 创建时间. */
  private @Column("create_time") LocalDateTime createTime;

  @Override
  public boolean isNew() {
    return _new;
  }

  /**
   * 返回未持久化的对象.
   *
   * <p>使用该方法创建的对象 {@link #isNew()} 方法始终应该返回 {@code true}.
   *
   * @return 未持久化对象
   */
  public static AuthAuthorizationCode fireNew() {
    var o = new AuthAuthorizationCode();
    o._new = true;
    return o;
  }
}
